var _Font = require('core/font.js').font;
var _Atlas = require('core/font.js').atlas;
var INIT = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~';

/**
 * @param width
 * @param height
 * @param basedir fonts/
 * @constructor
 */
function FontSuit(width, height, basedir) {
    this.mAtlas = new _Atlas(width, height, 1);
    this.mFontDb = {};
    this.mBasedir = basedir;
}
FontSuit.prototype.createFont = function (name, size, init) {
    var f = new _Font(this.mAtlas, this.mBasedir + name + '.ttf', size);
    var init = init || INIT;
    if (init.length > 0) {
        f.load(init || INIT);
    }
    return f;
};
/**
 * find or create font with name_size as its id
 *
 * @param name
 * @param size
 * @param init
 * @returns {*}
 */
FontSuit.prototype.findFont = function (name, size, init) {
    var id = name + '_' + size;
    return this.mFontDb[id] || (this.mFontDb[id] = this.createFont(name, size, init));
};
/**
 * find or create font with given id
 *
 * @param id
 * @param name
 * @param size
 * @param init
 * @returns {*}
 */
FontSuit.prototype.findFontById = function (id, name, size, init) {
    return this.mFontDb[id] || (this.mFontDb[id] = this.createFont(name, size, init));
};

module.exports = FontSuit;